package me.greyliu.kuai.controller;

import jakarta.servlet.http.HttpServletResponse;
import me.greyliu.kuai.entity.Response;
import me.greyliu.kuai.service.FTPService;
import org.apache.commons.net.ftp.FTPFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
@CrossOrigin(origins = "*")
public class FileController {
    @Autowired
    FTPService ftpService;
    @GetMapping("/file/list")
    @ResponseBody
    public FTPFile[] listFile(String path){
        return  ftpService.listFile(path);
    }
    @GetMapping("/file/download")
    @ResponseBody
    public void download(HttpServletResponse response, String path, String name){
        ftpService.download(response,path,name);
    }
    @PostMapping("/file/upload")
    @ResponseBody
    public Response upload( MultipartFile file,String location){
        return ftpService.upload(file,location);
    }
    @GetMapping("/file/getShare")
    @ResponseBody
    public void getShare(HttpServletResponse response, String id,String pwd){
            ftpService.getShare(response,id,pwd);
    }
}
